<nz-card>
  <nz-descriptions
    nzTitle="基本信息"
    nzBordered
    nzSize="small"
    [nzColumn]="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }"
  >
    <nz-descriptions-item nzTitle="单号">
      {{ detailsData.warehousingNumber || '-' }}
      <i
        *ngIf="detailsData.warehousingNumber"
        nz-icon
        nzType="copy"
        nzTheme="outline"
        nz-tooltip
        nzTooltipTitle="点击复制"
        (click)="coprText(detailsData.warehousingNumber)"
      ></i>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="状态">
      <span [ngStyle]="{'color': detailsData.state | storePutStatus: 'color'}">
        {{ detailsData.state | storePutStatus: 'label' }}
      </span>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="入库类型">
      <span>
        {{ filterText(putTypeOptions, detailsData.type, 'content') }}
      </span>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="新建人">{{ detailsData.founder || '-' }}</nz-descriptions-item>

    <nz-descriptions-item nzTitle="关联单号">
      {{ detailsData.purchaseNumber || '-' }}
      <i
        *ngIf="detailsData.purchaseNumber"
        nz-icon
        nzType="copy"
        nzTheme="outline"
        nz-tooltip
        nzTooltipTitle="点击复制"
        (click)="coprText(detailsData.purchaseNumber)"
      ></i>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="预计到货日期">{{ detailsData.arrivalTime || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="供应商">
      {{ filterText(supplierOptions, detailsData.supId, 'id') }}
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="新建时间">{{ detailsData.createTime || '-' }}</nz-descriptions-item>

    <nz-descriptions-item nzTitle="入库仓库">
      {{ filterText(warehouseOptions, detailsData.whPutId, 'id') }}
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="入库品质">
      <span>
        {{ detailsData.quality === 0 ? '不良品' : (detailsData.quality === 1 ? '良品' : '-') }}
      </span>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="入库完毕时间">{{ detailsData.warehousingTime || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="结案时间">{{ detailsData.endTime || '-' }}</nz-descriptions-item>

    <nz-descriptions-item nzTitle="附件" nzSpan="4">
      <ul>
        <li *ngFor="let item of detailsData?.fileList">
          {{ item.name }}
          <button
            nz-button
            nzType="link"
            nzSize="small"
            (click)="downFile(item)"
          >下载</button>
        </li>
      </ul>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="备注" nzSpan="4">{{ detailsData.remark || '-' }}</nz-descriptions-item>
  </nz-descriptions>
</nz-card>

<nz-card class="m-t-4">
  <p class="detail-title">入库明细</p>

  <div class="table-wrap">
    <nz-table
      #mxTable
      nzBordered
      nzSize="small"
      [nzShowPagination]="false"
      [nzFrontPagination]="false"
      [nzData]="warehousTableData">
      <thead>
        <tr>
          <th nzAlign="center" rowspan="2" nzWidth="70px">序号</th>
          <th nzAlign="center" colspan="4">商品信息</th>
          <ng-container *ngIf="detailsData.type == 1">
            <th nzAlign="center" colspan="3">采购信息</th>
          </ng-container>
          <th nzAlign="center" colspan="6">入库信息</th>
          <th nzAlign="center" rowspan="2">操作</th>
        </tr>
        <tr>
          <th nzAlign="center">商品状态</th>
          <th nzAlign="center">商品名称</th>
          <th nzAlign="center">商品编号</th>
          <th nzAlign="center">商品69码</th>
          <ng-container *ngIf="detailsData.type == 1">
            <th nzAlign="center">采购数量</th>
            <th nzAlign="center">冻结数量</th>
            <th nzAlign="center">已入库数量</th>
          </ng-container>
          <th nzAlign="center">行状态</th>
          <th nzAlign="center">预计入库数量</th>
          <th nzAlign="center">实际入库数量</th>
          <th nzAlign="center">入库库位</th>
          <th nzAlign="center">入库单价</th>
          <th nzAlign="center">小计</th>
        </tr>
      </thead>
      <tbody>
        <tr
          *ngFor="let data of mxTable.data; let index = index;"
          [ngClass]="{'tr-bg-red': data?.lineState === 1}">
          <!-- 序号 -->
          <td nzAlign="center">{{ index + 1 }}</td>
          <!-- 商品状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.whGoodsState === 0 ? '#999999' : '#67C23A'}">
              {{ data.whGoodsState === 0 ? '禁用' : (data.whGoodsState === 1 ? '启用' : '-') }}
            </span>
          </td>
          <!-- 商品名称 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.whGoodsState === 0 ? '#999999' : ''}">
              {{ data?.whGoodsName || '-' }}
            </span>
          </td>
          <!-- 商品编号 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.whGoodsState === 0 ? '#999999' : ''}">
              {{ data?.whGoodsCode || '-' }}
            </span>
          </td>
          <!-- 商品69码 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.whGoodsState === 0 ? '#999999' : ''}">
              {{ data?.whGoodsTwoCode || '-' }}
            </span>
          </td>

          <!-- ******* 采购入库显示 ****** -->
          <ng-container *ngIf="detailsData.type == 1">
            <!-- 采购数量 -->
            <td nzAlign="center">
              <span [ngStyle]="{'color': data?.purchaseNumber !== data?.stockNumber ? '#FF9900' : '' }">
                {{ data?.purchaseNumber || '0' }}
              </span>
            </td>
            <!-- 冻结数量 -->
            <td nzAlign="center">
              <span [ngStyle]="{'color': data?.purchaseNumber !== data?.stockNumber ? '#FF9900' : '' }">
                {{ data?.frozenNumber || '0' }}
              </span>
            </td>
            <!-- 已入库数量 -->
            <td nzAlign="center">
              <span [ngStyle]="{'color': data?.purchaseNumber !== data?.stockNumber ? '#FF9900' : '' }">
                {{ data?.stockNumber || '0' }}
              </span>
            </td>
          </ng-container>
          
          <!-- 行状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data?.lineState === 0 ? '#67C23A' : '#F56C6C'}">
              {{ data?.lineState === 0 ? '正常' : (data?.lineState === 1 ? '已作废' : '-') }}
            </span>
          </td>
          <!-- * 预计入库数量 -->
          <td nzAlign="center">
            {{ data?.number || '0' }}
          </td>
          <!-- 实际入库数量 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data?.actualStorageNumber !== data?.number ? '#F56C6C' : ''}">
              {{ data?.actualStorageNumber || '0' }}
            </span>
          </td>
          <!-- 入库库位 -->
          <td nzAlign="center">{{ data.libraryName || '-' }}</td>
          <!-- 入库单价 -->
          <td nzAlign="center">{{ data?.price || '0' }}</td>
          <!-- 小计 -->
          <td nzAlign="center">
            {{ calcProduct(data?.actualStorageNumber, data?.price) }}
          </td>
          <!-- 操作 -->
          <td nzAlign="center">
            <ng-container *ngIf="data?.lineState === 0; else elseTemplate">
              <button
                *ngIf="permission.userPermission.has('storageCenter:put:toVoid') && [2, 3, 4].includes(detailsData.state)"
                nz-button
                nzType="link"
                nzSize="small"
                nzDanger
                (click)="showTovoidModal(data)"
              >作废</button>

              <button
                *ngIf="data.itemSns"
                nz-button
                nzType="link"
                nzSize="small"
                (click)="showSnInfoModal(data)"
              >SN</button>

              <button
                *ngIf="data.libraryText"
                nz-button
                nzType="link"
                nzSize="small"
                (click)="showLocationModal(data)"
              >多库位</button>
            </ng-container>
            <ng-template #elseTemplate>
              -
            </ng-template>
          </td>
        </tr>

        <tr *ngIf="warehousTableData?.length" style="background: #fafafa; font-weight: 600;">
          <td nzAlign="center" colSpan="5">合计</td>
          <ng-container *ngIf="detailsData.type == 1">
            <td nzAlign="center">{{ calcSumTotal('purchaseNumber') }}</td>
            <td nzAlign="center">{{ calcSumTotal('frozenNumber') }}</td>
            <td nzAlign="center">{{ calcSumTotal('stockNumber') }}</td>
          </ng-container>
          <td nzAlign="center">-</td>
          <td nzAlign="center">{{ calcSumTotal('number') }}</td>
          <td nzAlign="center">{{ calcSumTotal('actualStorageNumber') }}</td>
          <td nzAlign="center">-</td>
          <td nzAlign="center">{{ calcSumTotal('price') }}</td>
          <td nzAlign="center">{{ calcProductTotal() }}</td>
          <td nzAlign="center">-</td>
        </tr>
      </tbody>
    </nz-table>
  </div>
</nz-card>

<nz-card class="m-t-4">
  <div nz-row nzJustify="center">
    <button
      nz-button
      nzType="default"
      (click)="pageBack()"
    >返回</button>
  </div>
</nz-card>

<!-- S SN信息 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [nzWidth]="800"
  [(nzVisible)]="isSninfoVisible"
  [nzTitle]="'SN信息'"
  (nzOnCancel)="isSninfoVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <nz-descriptions>
        <nz-descriptions-item nzTitle="商品编号">{{ snInfoItem?.whGoodsCode || '-' }}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="69码">{{ snInfoItem?.whGoodsTwoCode || '-' }}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="商品名称">{{ snInfoItem?.whGoodsName }}</nz-descriptions-item>
      </nz-descriptions>

      <div class="p-t-10">
        <nz-table
          #sninfoTable
          nzSize="small"
          nzBordered
          [nzShowPagination]="false"
          [nzData]="snInfoItem?.tableData">
          <thead>
            <tr>
              <th nzAlign="center" nzWidth="80px">序号</th>
              <th nzAlign="center">入库库位</th>
              <th nzAlign="center">SN码</th>
              <th nzAlign="center">备注</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of sninfoTable.data; let index = index;">
              <!-- 序号 -->
              <td nzAlign="center">{{ index + 1 }}</td>
              <!-- 入库库位 -->
              <td nzAlign="center">{{ data.name || '-' }}</td>
              <!-- SN码 -->
              <td nzAlign="center">{{ data.code || '-' }}</td>
              <!-- 备注 -->
              <td nzAlign="center">{{ data.remark || '-' }}</td>
            </tr>
          </tbody>
        </nz-table>
      </div>
    </div>
  </div>
</nz-modal>
<!-- S SN信息 Modal -->

<!-- S 多库位 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isDkwVisible"
  [nzTitle]="'多库位'"
  (nzOnCancel)="isDkwVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <nz-descriptions [nzColumn]="2">
        <nz-descriptions-item nzTitle="商品编号">{{ locationItem?.whGoodsCode || '-' }}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="69码">{{ locationItem?.whGoodsTwoCode || '-' }}</nz-descriptions-item>
        <nz-descriptions-item nzTitle="商品名称">{{ locationItem?.whGoodsName }}</nz-descriptions-item>
      </nz-descriptions>

      <div class="p-t-2">
        <nz-table
          #sninfoTable
          nzSize="small"
          nzBordered
          [nzShowPagination]="false"
          [nzData]="locationItem?.tableData">
          <thead>
            <tr>
              <th nzAlign="center" nzWidth="80px">序号</th>
              <th nzAlign="center">入库库位</th>
              <th nzAlign="center">入库数量</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of sninfoTable.data; let index = index;">
              <!-- 序号 -->
              <td nzAlign="center">{{ index + 1 }}</td>
              <!-- 入库库位 -->
              <td nzAlign="center">{{ data.name || '-' }}</td>
              <!-- 入库数量 -->
              <td nzAlign="center">{{ data.num || '0' }}</td>
            </tr>
          </tbody>
        </nz-table>
      </div>
    </div>
  </div>
</nz-modal>
<!-- S 多库位 Modal -->

<!-- S 作废 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isZfVisible"
  [nzTitle]="'提示'"
  (nzOnCancel)="isZfVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <p class="zf-tips">该操作不可逆，作废后该行彻底失效，已入库数量也不会被统计</p>
      
      <nz-form-item>
        <nz-form-label nzRequired>备注</nz-form-label>
        <nz-form-control>
          <nz-textarea-count [nzMaxCharacterCount]="100">
            <textarea
              rows="4"
              nz-input
              maxlength="100"
              placeholder="请输入备注、必填"
              [(ngModel)]="toVoidRemark"
            ></textarea>
          </nz-textarea-count>
        </nz-form-control>
      </nz-form-item>
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="default" (click)="isZfVisible = false">取消</button>
        <button nz-button nzType="primary" [nzLoading]="submitZfLoading" (click)="submitToVoidData()">确定作废</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- S 作废 Modal -->